<template>
  <div class="container">
    <normal-title
      title='订单详情'
      :back="true"
    ></normal-title>
    <div class="main">
      <div class="item-name">{{orderInfo.express_type==='1'?'自提地址':'快递地址'}}</div>
      <div class="row address-detail">
        <img
          class="addr-icon"
          src="../../images/address-icon.png"
          mode="aspectFit"
        >
        <div class="addr-content">
          <div class="row between ">
            <div class="addr-text">姓名：{{orderInfo.receiver_name}}</div>
            <div class="addr-text">电话：{{orderInfo.phone}}</div>
          </div>
          <div class="addr-text">{{orderInfo.province+orderInfo.city+orderInfo.country+orderInfo.address}}</div>
        </div>
      </div>
      <a
        :href="'/pages/detail/main?id='+item.product_id"
        hover-class="none"
        class="card"
        v-for="(item, index) in orderInfo.orderProduct"
        :key="index"
      >
        <img
          class="thumb"
          :src="item.image"
          mode="aspectFit"
        >
        <div class="info">
          <p class="text">{{item.product_name}}</p>
          <div class="spec">规格: {{item.item_no}}</div>
          <div class="row">
            <p class="price"><span class="price-icon">￥</span>{{item.price}}</p>
            <div class="count">X {{item.num}}</div>
          </div>
        </div>
      </a>
      <div class="row between">
        <div class="item-name">订单状态</div>
        <div class="order-num">{{orderStatus[orderInfo.order_status]}}</div>
      </div>
      <div class="row between start-item">
        <div>
          <div class="item-name">商品总额</div>
          <div>运费: ￥0</div>
        </div>
        <div class="col">
          <div>现价 ￥{{orderInfo.total_fee}}</div>
          <div v-if="orderInfo.userCoupon !==undefined && orderInfo.userCoupon.length >0">-优惠券 {{orderInfo.userCoupon[0].title}}</div>
          <div class="price">实付 ￥{{orderInfo.payment}}</div>
        </div>
      </div>
      <div class="row between">
        <div class="item-name">订单编号</div>
        <div class="order-num">{{orderInfo.order_no}}<span
            @click="copyOrderNum"
            class="copy"
          >复制</span></div>
      </div>

      <div class="row between">
        <div class="item-name">创建时间</div>
        <div class="order-num">{{orderInfo.created_at}}</div>
      </div>
      <div
        v-if="orderInfo.order_status==='0'"
        class="row right"
      >
        <div
          @click="payNow()"
          class="btn pay"
        >去支付</div>
      </div>
    </div>
    <bottom-btn />
  </div>
</template>

<script>
import NormalTitle from '@/components/NormalTitle'
import ProductCard from '@/components/ProductCard'
import BottomBtn from '@/components/BottomBtn'
import { request } from '@/utils'
import config from '@/config'
export default {
  components: {
    NormalTitle,
    ProductCard,
    BottomBtn
  },
  computed: {},
  data () {
    return {
      orderInfo: {},
      status: undefined,
      payying: false,
      orderStatus: config.orderStatus
    }
  },
  methods: {
    async getOrderInfo () {
      var orderId = this.$root.$mp.query.order_id
      var res = await request('/v1/order/' + orderId, 'get')
      this.orderInfo = res.data
    },
    copyOrderNum () {
      wx.setClipboardData({
        data: this.orderInfo.order_no
      })
    },
    async payNow () {
      var _this = this
      if (!this.payying) {
        var result = await request('/v1/pay', 'post', {
          orderId: this.$root.$mp.query.order_id
        })
        wx.requestPayment({
          timeStamp: result.data.timestamp,
          nonceStr: result.data.nonceStr,
          package: result.data.package,
          signType: 'MD5',
          paySign: result.data.paySign,
          complete (res) {
            _this.payying = false
            wx.redirectTo({
              url:
                '/pages/orderDetail/main?order_id=' +
                _this.$root.$mp.query.order_id
            })
          }
        })
      }
    }
  },
  mounted () {
    this.getOrderInfo()
  }
}
</script>

<style>
page {
  height: 100%;
}
</style>

<style scoped lang="scss">
.container {
  font-size: 26rpx;

  color: #6d6d6d;
  .main {
    padding: 0 25rpx;
    .card {
      .row {
        margin: 0;
      }
      font-size: 26rpx;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      height: 200rpx;
      border-bottom: 1rpx solid #f0f0f0;
      .thumb {
        width: 160rpx;
        height: 160rpx;
        border-radius: 15rpx;
        margin-right: 30rpx;
      }
      .info {
        width: 460rpx;
        height: 160rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        // border: 1rpx solid #000;
        .spec {
          font-size: 20rpx;
          color: #747474;
          margin-bottom: 5rpx;
          overflow: hidden;
          text-overflow: ellipsis;
          position: relative;
          bottom: 10rpx;
        }
        .text {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          height: 75rpx;
          font-size: 600;
          color: #000;
        }
        .row {
          display: flex;
          justify-content: space-between;
          align-items: flex-end;
          height: 35rpx;
          line-height: 26rpx;
          .price {
            color: #b93a39;
            font-size: 36rpx;
            font-weight: 400;
            .price-icon {
              font-size: 24rpx;
              display: inline-block;
            }
          }
          .count {
            font-size: 20rpx;
          }
        }
      }
    }
    .row {
      margin: 35rpx 0;
    }
    .address-detail {
      background: #f6f6f6;
      padding: 20rpx 30rpx;
      border-radius: 15rpx;
      margin-bottom: 20rpx;
      .addr-icon {
        width: 40rpx;
        height: 40rpx;
        padding-right: 25rpx;
      }
      .addr-content {
        width: 580rpx;
        .row {
          margin: 0;
        }
      }
      .addr-text {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 24rpx;
        line-height: 40rpx;
      }
    }
    .item-name {
      font-size: 32rpx;
      font-weight: 500;
      color: #000;
    }
    .col {
      text-align: right;
      .price {
        color: #b93a39;
        font-weight: 600;
      }
    }
    .order-num {
      font-size: 30rpx;
      .copy {
        color: #d9c59d;
        display: inline-block;
        margin-left: 30rpx;
        text-decoration: underline;
      }
    }
    .right {
      justify-content: flex-end;
    }
    .btn {
      font-size: 26rpx;
      height: 50rpx;
      border-radius: 30rpx;
      text-align: center;
      line-height: 46rpx;
      margin-left: 20rpx;
      width: 150rpx;
    }
    .cancel {
      border: 1rpx solid #6d6d6d;
      color: #6d6d6d;
    }
    .pay {
      border: 1rpx solid #cdb27e;
      color: #cdb27e;
    }
  }
}
</style>




